/*
 * 全时云商务服务股份有限公司.
 * Copyright © 2021 京icp备08005473号. All rights reserved.
 * @Date: 2021-09-02.
 * @Author：
 * @Description 小课堂 - 课程节次时间列表 - 组件
 **/
import React, { memo } from "react"
import Taro from '@tarojs/taro'
import { AtMessage } from 'taro-ui'
import { View, Text } from '@tarojs/components'
import './index.scss'

interface Props {
  detailUrl: string // 详情页地址
  status: string
  id?: string // 设置项的 key值
  label?: string // label
}
/**
 *@Description
 *@Return  课程节次.
 **/
 const SectionList: React.FC<Props> = props => {

   /**
   *@Description
  *@Return  点击 课程列表 - 状态按钮 - 事件监听.
  **/
 const handleStatusClick = (status) => {
   switch (status.status) {
     case "ing":
      Taro.atMessage({
        'message': '课程还未开始',
        'type': "warning",
      })
      break;
    case "coming":
      Taro.atMessage({
        'message': '课程已经开始',
        'type': "warning",
      })
      break;
      case "no":
        Taro.atMessage({
          'message': '课程还未开始',
          'type': "warning",
        })
      break;
      case "play":
        Taro.redirectTo({
          url: status.detailUrl,

          success: function (res) {
            // 通过eventChannel向被打开页面传送数据
            console.log(5252525, res)
          }
        })
      break;

     default:
       break;
   }

 }

   return (
    <View className='cou-time-list'>
      {/* 消息提示必须引入 */}
      <AtMessage />
      <Text>第一讲</Text> 8月1日 (周四) 14:00 - 15:00
      {props.status === "ing" && (<Text onClick={() => handleStatusClick(props)} className='cou-btn btn-gray'>已上课</Text>)}
      {props.status === "coming" && (<Text onClick={() => handleStatusClick(props)} className='cou-btn btn-green'>即将上课</Text>)}
      {props.status === "no" && (<Text onClick={() => handleStatusClick(props)} className='cou-btn btn-gray'>未开课</Text>)}
      {props.status === "play" && (<Text onClick={() => handleStatusClick(props)} className='cou-btn btn-white'>查看回放</Text>)}

    </View>
   )
 }

export default memo(SectionList)

